package iscript.gameFramework.GameLite.graphics 
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import iscript.gameFramework.GameLite.events.GraphicsDeviceManagerEvent;
	import iscript.gameFramework.GameLite.graphics.animation.BitmapBatchManager;
	
	
	[Event(name="resize",type="iscript.gameFramework.GameLite.events.GraphicsDeviceManagerEvent")]
	
	public class GraphicsDeviceManager extends EventDispatcher
	{
		
		private var _gameStage:Stage;
		private var _bitmapBatchManager:BitmapBatchManager;
		
		public function GraphicsDeviceManager(stage:Stage) 
		{
			_gameStage = stage;
			_gameStage.addEventListener(Event.RESIZE,_gameScreenResizeLogic)
			_bitmapBatchManager = new BitmapBatchManager();
		}
		
		private function _gameScreenResizeLogic(e:Event):void 
		{
			var event:GraphicsDeviceManagerEvent = new GraphicsDeviceManagerEvent(GraphicsDeviceManagerEvent.RESIZE);
			    event.gameScreenRect = new Rectangle(0, 0, _gameStage.stageWidth, _gameStage.stageHeight);
			this.dispatchEvent(event);
		}
		
		public function get fps():int { return _gameStage.frameRate; }
		
		public function get stage():Stage { return _gameStage; }
		
		public function get supportGPU():Boolean { return  false; }		
		
		public function get IsFullScreen():Boolean{
			  return _gameStage.displayState == StageDisplayState.FULL_SCREEN;
			}
			
		public function get bitmapBatchManager():BitmapBatchManager { return _bitmapBatchManager; }
		
		/**
		 * 转换为全局坐标
		 * @param	target
		 * @return
		 */
		public function toDevicePoint(target:DisplayObject):Point {
			   var result:Point = new Point(); 
			   while ( target != null) {
					    result.x += target.x;
						result.y += target.y;
						target = target.parent
					 }
			     return  result;
			}
	}

}